// 斜率优化
// https://soj.turingedu.cn/problem/51100/
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 5e4;
#define POW(i) (ll(i) * (i))
#define B_(j) (pre[j] + j)
#define A_(i) (pre[i] + i - L - 1)
#define Y_(j) (dp[j] + POW(B_(j)))
#define X_(j) (B_(j))
#define K_(i) (2 * A_(i))

int n, L;
ll a[maxn];
ll pre[maxn];
ll dp[maxn];

int qe[maxn], head, tail;
inline double slope(int i, int j) { return (Y_(i) - Y_(j)) / double(X_(i) - X_(j)); }

bool check(ll x, ll y) {
    // (x1, y1) -- (x2, y2) -- (x, y)
    ll x1 = X_(qe[tail - 2]), y1 = Y_(qe[tail - 2]); // (x1, y1)
    ll x2 = X_(qe[tail - 1]), y2 = Y_(qe[tail - 1]); // (x2, y2)
    // 比较斜率 (y - y2) / (x - x2) ? (y2 - y1) / (x2 - x1)
    return (y - y2) * (x2 - x1) <= (y2 - y1) * (x - x2);
}

void insert(int pos) {
    while (tail - head >= 2 && check(X_(pos), Y_(pos)))
        --tail;
    qe[tail++] = pos;
}

void keep(int i) {
    while (tail - head >= 2 && (Y_(qe[head + 1]) - Y_(qe[head])) <= (X_(qe[head + 1]) - X_(qe[head])) * K_(i))
        ++head;
}

void init() {
    head = 0, tail = 0;
    memset(dp, inf, sizeof(dp));
    dp[0] = 0;
    qe[tail++] = 0;
}

int main() {
    // freopen("t.in", "r", stdin);
    // freopen("ans.txt", "w", stdout);
    n = rad(), L = rad();
    rf(i, n) a[i] = rad(), pre[i] = pre[i - 1] + a[i];
    init();
    rf(i, n) {
        keep(i);
        int j = qe[head];
        dp[i] = dp[j] + POW((A_(i) - B_(j)));
        insert(i);
    }
    printf("%lld", dp[n]);
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}